#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys,re
import time
from sheepomatic_io import Brief_file_replacer

#
def main(args):
    """Replaces the given value in the brief file and rewrites it to std output

    Parameters:
    filename -- the name of the brief file
    index -- the index of the column/attribute (counting from 1) to replace in
    pattern -- the string to replace
    replacement -- the string to replace the pattern with
    """
    filename = args[0]
    index = args[1]
    pattern = args[2]
    replacement = args[3]
    # read and norm sheep
    Brief_file_replacer.replace_value(filename,index,pattern,replacement)

if __name__ == '__main__':
    args = sys.argv[1:]
    if len(args) == 4:
       main(args)
    else:
       print >> sys.stderr, "Wrong number of parameters."
       print >> sys.stderr, "Usage:"
       print >> sys.stderr, "replace_sheep_value.py brief_file_name col_index pattern_to_replace new_value"
       sys.exit(1)
